package com.view;

import android.databinding.DataBindingUtil;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;

import com.base.mvvm2.MVVMBaseActivity2;
import com.gml.gao.R;
import com.gml.gao.databinding.CommonRecyclview2Binding;
import com.gml.gao.databinding.CommonRecyclviewBinding;
import com.view.Model.RecycleViewModle2;
import com.view.inject.DaggerRecyclViewComponet;
import com.view.loadmore.EndLessOnScrollListener;


/**
 * Created by gml on 17/2/21.
 */

public class RecyclViewActivity2 extends MVVMBaseActivity2<RecycleViewModle2> {


    private CommonRecyclview2Binding binding;
    private LinearLayoutManager layoutManager;



    @Override
    protected void initInjector() {
        DaggerRecyclViewComponet.builder()
                .appComponent(getAppComponent())
                .activityModule(getActivityModule())
                .build()
                .inject(this);
    }
    @Override
    public void initView() {

        binding = DataBindingUtil.setContentView(this, R.layout.common_recyclview2);
        binding.setLvAdapter(mPresenter.gettSimpleAdapter());
        layoutManager = new LinearLayoutManager(this);
        binding.recyclerView.setLayoutManager(layoutManager);//这里用线性显示 类似于listview
//        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));//这里用线性宫格显示 类似于grid view
//        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, OrientationHelper.VERTICAL));//这里用线性宫格显示 类似于瀑布流

//        List<Employee> demoList = new ArrayList<>();
//        demoList.add(new Employee("Zhai", "Mark", false));
//        demoList.add(new Employee("Zhai2", "Mark2", false));
//        demoList.add(new Employee("Zhai3", "Mark3", true));
//        demoList.add(new Employee("Zhai4", "Mark4", false));
//        madapter.addAll(demoList);

//        binding.setLvAdapter(mPresenter.gettSimpleAdapter());

        mPresenter.findall();
        binding.swiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.findall();
                binding.swiperefreshlayout.setRefreshing(false);
            }
        });


        /**
         * 监听addOnScrollListener这个方法，新建我们的EndLessOnScrollListener
         * 在onLoadMore方法中去完成上拉加载的操作
         * */
        binding.recyclerView.addOnScrollListener(new EndLessOnScrollListener(layoutManager) {
            @Override
            public void onLoadMore(int currentPage) {
                mPresenter.findall();
            }
        });
    }
}
